package com.mypro._01base.test;

import com.github.pagehelper.Page;
import com.mypro._01base.dbutil.DbUtil;
import com.mypro._01base.entity.Emp;
import com.mypro._01base.mapper.EmpMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * @author user_xdd
 * @Date 2022-05-14 17:26
 * @description 一个分页工具
 * @return
 */
public class PageHelper {
        private static  final Logger LOGGER = Logger.getLogger(PageHelper.class);
    public static void main(String[] args) {

        SqlSession session = DbUtil.getSqlSession();
        EmpMapper empMapper = session.getMapper(EmpMapper.class);

        com.github.pagehelper.PageHelper.startPage(3, 2);//以每页2行的模式 查看第二页
        Page<Emp> page = (Page<Emp>) empMapper.queryAll();
        List<Emp> empList = page.getResult();
        for (Emp emp : empList) {
             LOGGER.debug("    emp:"+emp);
        }

        System.out.println("总行数:" + page.getTotal());
        System.out.println("总页数:" + page.getPages());


        session.close();
    }
}
